/***************************************************************************
 *   Copyright (C) 2008 by JBox systems
 *   gabi@shaargiora.co.il
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 ***************************************************************************/

#pragma once

#include <QXmlDefaultHandler>
#include <map>
#include <vector>

#include "version.h"

/**
	Import installer template.

*/
class ImportHandler : public QXmlDefaultHandler {
	private:

		QString m_data; /// Character data from xml file
		std::map<QString, QString> m_attributes; /// Element attributes
		bool inTemplate; /// for validity
		std::vector<Version> m_application_list; /// Vector to store all versions that are found.

		std::map<QString, short> element_lookup; /// Names of element types.

	public:

		enum Elements {Install, Run, Include, Command, Service, Setting, Update, Registry};

		ImportHandler();

		bool startElement (const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &atts );
		bool endElement (const QString &namespaceURI, const QString &localName, const QString &qName );
		bool characters (const QString &ch );

		/**
			Get all the versions to install.
			@return vector of versions to instal..
		*/
		//FIXME: I highly suggest to bundle all of the outputs into some struct and ship out in single method.
		std::vector<Version> installList() const { return m_application_list; }
};
